﻿@{
    ViewBag.Title = "EmployeeInfo";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <link href="~/Scripts/miniui/themes/default/medium-mode.css" rel="stylesheet" type="text/css" />       
    <style  type="text/css">
        body {
            font-size:10pt  !important;
        }
        td {
            vertical-align:bottom !important;
        }
    </style>
}

<form id="form1" method="post">
        @Html.Partial("~/Views/Modular/Toolbars.cshtml")
        <div name="Base" title="门店资料" style="height:100%;overflow:hidden;margin-top:10px;margin-left:20px">
            <table >
                <tr>
                    <td width="80px" height ="35px" align="right">导购编码：</td>
                    <td width="200px" height ="35px">
                        <input name="FNumber" id="FNumber" class="mini-textbox" selectOnFocus="true" style="width:200px;" value="" TabIndex="1"/>
                    </td>
                     <td width="100px" height ="35px" align="right">其它说明：</td>
                    <td width="350px" height ="35px">
                        <input id="FRemark" name="FRemark" class="mini-textbox " selectOnFocus="true" style="width:355px;" TabIndex="5"/>
                    </td>
               </tr>
                <tr>
                     <td width="80px" height ="35px" align="right">导购姓名：</td>
                    <td width="200px" height ="35px">
                        <input id="FName" name="FName" class="mini-textbox " selectOnFocus="true" style="width:200px;" TabIndex="2"/>
                    </td>
                    <td width="100px" height ="35px" align="right">商品销售提成：</td>
                    <td width="350px" height ="35px">
                        <input id="FSalePer" name="FSalePer" class="mini-spinner " style="width:70px;" TabIndex="7"  changeOnMousewheel ="false" 
                            showbutton="false" increment ="0.01" selectOnFocus="true" format="#,0.00##" minValue="0" maxValue="1" value="0"/> 
                        <input id="FPerType" name="FPerType" class="mini-combobox" style="width:280px;" showNullItem="false" 
                            allowInput="false" align="left" value ="0" data ="comType" tabindex="6" onvaluechanged="onChanged()"/> 
                    </td>
                </tr>
                <tr>
                     <td width="80px" height ="35px" align="right">联系电话：</td>
                    <td width="200px" height ="35px">
                        <input id="FTelephone" name="FTelephone" class="mini-textbox " selectOnFocus="true" style="width:200px;" TabIndex="3"/>
                    </td>
                    <td width="100px" height ="35px" align="right">会员充值提成：</td>
                    <td width="350px" height ="35px">
                        <input id="FRecPer" name="FRecPer" class="mini-spinner " style="width:70px;" TabIndex="8"  changeOnMousewheel ="false" 
                            showbutton="false" increment ="0.01" selectOnFocus="true" format="#,0.00##"  minValue="0" maxValue="1" value="0"/> 
                        <input id="FRecPerType" name="FRecPerType" class="mini-combobox" style="width:280px;" showNullItem="false" 
                            allowInput="false" align="left" value ="0" data ="comRecType" tabindex="6" onvaluechanged="onRecChanged()"/> 
                    </td>
                </tr>
                <tr>
                     <td width="80px" height ="35px" align="right">居住地址：</td>
                    <td width="200px" height ="35px">
                        <input id="FAddress" name="FAddress" class="mini-textbox " selectOnFocus="true" style="width:200px;" TabIndex="4"/>
                    </td>
                    <td width="100px" height ="35px" align="right">次卡提成：</td>
                    <td width="350px" height ="35px">
                         <input id="FTimePer" name="FTimePer" class="mini-spinner " style="width:70px;" TabIndex="9" changeOnMousewheel="false"
                                showbutton="false" increment="0.01" selectOnFocus="true" format="#,0.00##" minValue="0" maxValue="1" value="0" />
                        <input id="FTimePerType" name="FTimePerType" class="mini-combobox" style="width:280px;" showNullItem="false" 
                            allowInput="false" align="left" value ="0" data ="comTimeType" tabindex="6" onvaluechanged="onTimeChanged()"/> 
                    </td>
                </tr>
                <tr>
                     <td width="80px" height ="35px" align="right">在职状态：</td>
                    <td width="200px" height ="35px">
                        <input id="FState" name="FState" class="mini-combobox" style="width:200px;" showNullItem="false" 
                            allowInput="false" align="left" value ="1" data ="comState" tabindex="10"/> 
                    </td>
                    <td width="100px" height ="35px" align="right">说明：</td>
                     <td width="350px" height="35px">1、提成系数请输入小数点的数值，0.1表示10%
                     </td>
                     
                </tr>
                <tr>
                    <td width = "80px" height ="35px" align="right">关联用户：</td>
                    <td width = "200px" height ="35px">
                        @Html.Partial("~/Views/Modular/LookupUserEmploy.cshtml")
                    </td>
                    <td width="100px" height ="35px" align="right"></td>
                     <td width="350px" height="35px">2、会员充值提成包括会员充值和购买服务的提成。
                     </td>
                </tr>
                <tr>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px">      
                        <div id="FAddUserFlag" name="FAddUserFlag" class="mini-checkbox" 
                            style ="margin-right:20px;font-size:12pt;" value ="false" text="同时新增关联用户">
                        </div>                  
                    </td>
                    <td width="100px" height ="35px" align="right"></td>
                     <td width="350px" height="35px">3、关联用户用于小程序登录查看导购员报表。
                     </td>
                </tr>
            </table>
            <br />
        </div>
    <input name="FItemID" class="mini-hidden" />
</form>

<script>
        var comType = [{ "id": "0", "text": "不提成" },
                   { "id": "1", "text": "按商品资料提成系数计算" },
                { "id": "2", "text": "按本【商品销售提成】计算" }];

        var comRecType = [{ "id": "0", "text": "不提成" },
                   { "id": "1", "text": "按本【会员充值提成】计算(余额充值)" },
                   { "id": "2", "text": "按本【会员充值提成】计算(次卡充值)" },
                   { "id": "3", "text": "按本【会员充值提成】计算(余额和次卡充值)" }];

        var comTimeType = [{ "id": "0", "text": "不提成" },
                   { "id": "1", "text": "按次卡方案充值时计算" },
                    { "id": "2", "text": "按次卡方案消费时计算" },
                   { "id": "3", "text": "按本【次卡提成】充值时计算" },
                    { "id": "4", "text": "按本【次卡提成】消费时计算" }];

    var comState = [{ "id": "1", "text": "在职" }, { "id": "0", "text": "离职" }];
    var msg = '';
    mini.parse();
    function SetInfoData(data) {
        if (data.action == "new") {
            mini.getbyName("FItemID").setValue('0');
            mini.get("FAddUserFlag").setEnabled(true);
            NewInfo();
        }
        else {
            $.post("GetEmployee", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                mini.getbyName("FUserID").setText(mdata.data[0].FUserNumber);
                form.setData(mdata.data[0]);
                mini.getbyName("FNumber").setEnabled(false);
                if (mdata.data[0].FPerType == null) {
                    mini.get("FPerType").setValue(0);
                }
                if (mdata.data[0].FState == null) mini.get("FState").setValue(1);                    
                onChanged(mdata.data[0].FPerType);
                onRecChanged(mdata.data[0].FRecPerType);
                onTimeChanged(mdata.data[0].FTimePerType);
                mini.get("FAddUserFlag").setEnabled(false);
            });
       }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        mini.getbyName("FName").setValue("");
        mini.getbyName("FTelephone").setValue("");
        mini.getbyName("FAddress").setValue("");
        mini.getbyName("FRemark").setValue("");
        mini.getbyName("FSalePer").setValue(0);
        mini.getbyName("FRecPer").setValue(0);
        mini.getbyName("FTimePer").setValue(0);
        mini.get("FState").setValue("1");
        var jsonstr = '{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}';
        $.post('NewEmployeeInfo', { json: jsonstr }, function (data) {
            mini.getbyName("FNumber").setValue(data);
        });
        onChanged();
    }

    //保存资料
    function SaveInfo() {
        mini.getbyName("SaveInfo").setEnabled(false);
        if (!validata()) {
            mini.alert(msg);
            mini.getbyName("SaveInfo").setEnabled(true);
            return;
        }
        var form = new mini.Form("#form1");
        var data = form.getData(true, false);

        var json = mini.encode(data);
        $.post("SaveInfo", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                NewInfo();
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            mini.getbyName("SaveInfo").setEnabled(true);
        });
    }

    function validata() {
        if (mini.getbyName("FNumber").getValue() == '') {
            msg = '导购编码不能为空';
            return false;
        }
        if (mini.getbyName("FName").getValue() == '') {
            msg = '导购姓名不能为空';
            return false;
        }
        if (mini.getbyName("FTelephone").getValue() == '') {
            msg = '联系电话不能为空';
            return false;
        }
        if (mini.getbyName("FNumber").getValue().length > 50) {
            msg = '导购编码不能大于50个字符';
            return false;
        }
        if (mini.getbyName("FName").getValue().length > 50) {
            msg = '导购姓名不能大于50个字符';
            return false;
        }
        if (mini.getbyName("FTelephone").getValue().length > 50) {
            msg = '联系电话不能大于50个字符';
            return false;
        }
        return true;
    }

    function onChanged(value) {
        var vs = value == undefined ? mini.get("FPerType").getValue() : value;
        if (vs < 2) {
            mini.getbyName("FSalePer").setValue(0);
            mini.getbyName("FSalePer").setEnabled(false);
        }
        else
            mini.getbyName("FSalePer").setEnabled(true);
    }

    function onRecChanged(value) {
        var vs = value == undefined ? mini.get("FRecPerType").getValue() : value;
        if (vs < 1) {
            mini.getbyName("FRecPer").setValue(0);
            mini.getbyName("FRecPer").setEnabled(false);
        }
        else
            mini.getbyName("FRecPer").setEnabled(true);

    }
    function onTimeChanged(value) {
        var vs = value == undefined ? mini.get("FTimePerType").getValue() : value;
        if (vs < 3) {
            mini.getbyName("FTimePer").setValue(0);
            mini.getbyName("FTimePer").setEnabled(false);
        }
        else
            mini.getbyName("FTimePer").setEnabled(true);
    }
    
</script>